package com.lz.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lz.domain.TblApplicationInfo;
import com.lz.service.TblApplicationInfoService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TblApplicationInfo)表控制层
 *
 * @author makejava
 * @since 2024-04-14 14:38:14
 */
@RestController
@RequestMapping("tblApplicationInfo")
public class TblApplicationInfoController {
    /**
     * 服务对象
     */
    @Resource
    private TblApplicationInfoService tblApplicationInfoService;

    /**
     * 分页查询
     *
     * @param tblApplicationInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TblApplicationInfo>> queryByPage(TblApplicationInfo tblApplicationInfo, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tblApplicationInfoService.queryByPage(tblApplicationInfo, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TblApplicationInfo> queryById(@PathVariable("id") String id) {
        return ResponseEntity.ok(this.tblApplicationInfoService.queryById(id));
    }

    @RequestMapping("/test")
    public PageInfo<TblApplicationInfo>  test(){
        PageHelper.startPage(1, 10).setReasonable(true);
        List<TblApplicationInfo> tblApplicationInfos = tblApplicationInfoService.queryAll();
        PageInfo<TblApplicationInfo> tblApplicationInfoPageInfo = new PageInfo<>(tblApplicationInfos);
        List<TblApplicationInfo> list = tblApplicationInfoPageInfo.getList();
        int pageNum = tblApplicationInfoPageInfo.getPageNum();
        int pageSize = tblApplicationInfoPageInfo.getPageSize();
        int pages = tblApplicationInfoPageInfo.getPages();
        System.out.println(pageNum+"====="+pageSize+"======"+pages);
        System.out.println("\n");
        System.out.println(list);

        return tblApplicationInfoPageInfo;
    }

    /**
     * 新增数据
     *
     * @param tblApplicationInfo 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TblApplicationInfo> add(TblApplicationInfo tblApplicationInfo) {
        return ResponseEntity.ok(this.tblApplicationInfoService.insert(tblApplicationInfo));
    }

    /**
     * 编辑数据
     *
     * @param tblApplicationInfo 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TblApplicationInfo> edit(TblApplicationInfo tblApplicationInfo) {
        return ResponseEntity.ok(this.tblApplicationInfoService.update(tblApplicationInfo));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String id) {
        return ResponseEntity.ok(this.tblApplicationInfoService.deleteById(id));
    }

}

